//
//  FrouToastController.m
//  OnionHome
//
//  Created by fengjie on 2019/9/20.
//  Copyright © 2019 FengJie. All rights reserved.
//

#import "FrouToastController.h"

@interface FrouToastController ()
/**输入框*/
@property (nonatomic,strong)PubulicTextView*textView;
/**输入文字个数*/
@property (nonatomic,strong)UILabel*numberLabel;
@end

@implementation FrouToastController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createUI];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTextAction) name:UITextViewTextDidChangeNotification object:nil];
}
-(void)changeTextAction{
    self.numberLabel.text = [NSString stringWithFormat:@"%lu/50",(unsigned long)self.textView.textView.text.length];
}
-(void)createUI{
    self.isHidenNaviBar = YES;
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect: self.view.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(15,15)];
    //创建 layer
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = self.view.bounds;
    //赋值
    maskLayer.path = maskPath.CGPath;
    self.view.layer.mask = maskLayer;
    
    
    UIView * headerView = [self createHeaderView];
    headerView.backgroundColor = KWhiteColor;
    
    [self.view addSubview:headerView];
    [self.view addSubview:self.textView];
    [self.textView addSubview:self.numberLabel];

    [headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_equalTo(0);
        make.height.mas_equalTo(50);
    }];
    [self.textView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.right.mas_equalTo(-16);
        make.bottom.mas_equalTo(-20);
        make.top.mas_equalTo(headerView.mas_bottom);
    }];

    [self.numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(0);
        make.bottom.mas_equalTo(-10);
    }];
}

-(UIView *)createHeaderView{
    UIView * view = UIView.new;
    
    UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setTitle:@"X" forState:UIControlStateNormal];
    [button setTitleColor:KBlackColor forState:UIControlStateNormal];
    kWeakSelf(weakSelf);
    [button addActionHandler:^{
        [weakSelf backBtnClicked];
    }];
    UIButton * button1 = [UIButton buttonWithType:UIButtonTypeCustom];
    [button1 setTitle:@"发布" forState:UIControlStateNormal];
    [button1 setTitleColor:UIColorFromRGB(0x959E97) forState:UIControlStateNormal];
    
    [button1 addActionHandler:^{
        if (!StrValid(weakSelf.textView.textView.text)) {
            ShowHubMessage(@"请输入具体内容");
            return ;
        }
        [weakSelf backBtnClicked];
        BlockSafeRun(weakSelf.releseBlock);
    }];

    UILabel * label = UILabel.new;
    label.text = @"我要吐糟";
    label.textAlignment = NSTextAlignmentCenter;
    label.font = SYSTEMFONT(16);
    label.textColor = UIColorFromRGB(0x273323);
    
    [view addSubview:button];
    [view addSubview:label];
    [view addSubview:button1];

    [button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.centerY.mas_equalTo(0);
    }];
    [button1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-16);
        make.centerY.mas_equalTo(0);
    }];

    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(0);
    }];
    
    return view;
}
-(PubulicTextView*)textView{
    if(!_textView){
        _textView=[PubulicTextView new];
        _textView.placeholderText.text = @"请说明具体的问题，我们将尽快处理";
        _textView.placeholderText.textColor = UIColorFromRGB(0x959E97);
    }
    return _textView;
}
-(UILabel*)numberLabel{
    if(!_numberLabel){
        _numberLabel=[UILabel new];
        _numberLabel.textColor = UIColorFromRGB(0x959E97);
        _numberLabel.font = SYSTEMFONT(12);
        _numberLabel.text = @"0/50";
    }
    return _numberLabel;
}
@end
